﻿// -- FILE ------------------------------------------------------------------
// name       : CommandCollection.cs
// created    : Jani Giannoudis - 2008.04.15
// language   : c#
// environment: .NET 3.0
// --------------------------------------------------------------------------
using System;
using System.Windows.Input;
using System.Collections.Generic;
using System.Collections.ObjectModel;

namespace OpenExpressApp.Command
{
    /// <summary>
    /// 命令的集合
    /// </summary>
    public class CommandCollection : Collection<CommandBase>
    {
        public CommandCollection() { }

        /// <summary>
        /// 根据命令名查找命令
        /// </summary>
        /// <param name="name"></param>
        /// <returns></returns>
        public CommandBase this[string id]
        {
            get
            {
                if (string.IsNullOrEmpty(id) == false)
                {
                    foreach (CommandBase command in this)
                    {
                        if (id.Equals(command.Id))
                        {
                            return command;
                        }
                    }
                }
                return null;
            }
        }

        /// <summary>
        /// 是否包含指定名字的命令。
        /// </summary>
        /// <param name="name"></param>
        /// <returns></returns>
        public bool Contains(string id)
        {
            return this[id] != null;
        }
    }
}